# 函数返回多个数据值
# def clac(a, b):
#     return a + b, a - b
#
#
# C = clac(10, 20)
# print(C[1])


# 函数传参的方式
## 位置传参
# def show_info(name, age):
#     print(f'naem:{name}\nage:{age}')
#
#
# #位置传参
# show_info('wangwu', 18)
# # 关键字传参
# show_info(name='wangwu', age = 18)
# #混合使用
# show_info('wangwu',age = 18)


# 缺省参数
# def show_info(name, age=18, sex='保密'):
#     print(name, age, sex)
#
#
# show_info('张三', sex='男', age=18)
# show_info('王五')
# show_info('李四', 22)
# show_info('小明', sex='男')


# 多值参数
# def show_info(*args):
# #     print(args)
# #
# #
# # show_info()
# # show_info('张三', 18, '男')


# def my_sum(*args):
#     num = 0
#     for i in args:
#         num = num + i
#     return num
#
#
# a = my_sum(1,2,3,4)
# print(a)
# # 想要把列表(元组)中的数据作为位置参数进行传递,只需要在列表(元组)前边加上一个*,进行拆包即可
# my_list = [1,2,3,4,5]
# print(my_sum(*my_list))

# 匿名函数 lambda
# func = lambda a, b: a + b
# print(func(1, 2))
# abc = lambda a, b: a * b
# print(abc(2, 5))
#
# bcd = lambda x: x['age']
# a = {"name": '王醒', 'age': 18}
# print(bcd(a))

# user_list = [
#     {'name': '张三', 'age': 22, 'title': '测试工程师'},
#     {'name': '李四', 'age': 24, 'title': '开发工程师'},
#     {'name': '王五', 'age': 21, 'title': '测试工程师'}
# ]
# for i in range(3):
#     print(user_list[i]['age'])
# user_list.sort(key=lambda x: x['age'])
# print(user_list)
#
#
# def abc(x):
#     return x['age']
#
#
# user_list.sort(key=abc)
# print(user_list)


def make_student():
    """录入单个学生信息"""
    a = input('姓名:')
    b = int(input('年龄:'))
    dict1 = {"name": a, 'age': b}
    return dict1


def show_info():
    """打印信息"""
    print('---------学生信息---------')
    i = 1
    for stu in list1:
        print(f'{i}\t{stu['name']}\t{stu['age']}')
        i += 1
    print('-------------------------')


def get_count():
    """统计学生总数"""
    return len(list1)


def search_student():
    """查询学生信息"""
    name = input('请输入要查询的学生姓名:')
    for i in list1:
        if i['name'] == name:
            print(f'姓名:{i['name']}\t年龄:{i['age']}')
            return
    print(f'对不起,名字叫{name}的学生不存在')


list1 = [[{'name': 'aa', 'age': 11}, {'name': 'bb', 'age': 22}, {'name': 'cc', 'age': 33}]
]
if __name__ == '__main__':
    # for i in range(3):
    #     stu = make_student()
    #     list1.append(stu)
    #     print(list1)
    # show_info()
    # print(f'学生总人数:{get_count()}')
    # search_student()
    print('-------1.添加  2.打印   3.总人数  4.查询  0.退出-------')
    a = input('请选择:')
    while 1:
        if a == '1':
            make_student()
        elif a == '2':
            show_info()
        elif a == '3':
            get_count()
        elif a == '4':
            search_student()
        elif a == '0':
            break
        else:
            print('选择错误,请重新选择!')

